/*
 * @Description:
 * @Author: YaoXiaotTian
 * @Date: 2021-04-17 15:30:32
 * @LastEditors: YaoXiaoTian
 * @LastEditTime: 2021-05-26 15:41:13
 */
// var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
// const mysql = require("mysql");

var indexRouter = require("./routes/index");
const { request } = require("http");
const { response } = require("express");
// var usersRouter = require("./routes/users");

var app = express();
// 跨越请求必须放在实例化之后，否则不生效
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  //Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
  res.header(
    "Access-Control-Allow-Headers",
    "content-Type,token,Authorization "
  );
  res.header("Access-Control-Allow-Methods", "*");
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use(indexRouter);

app.listen(3000, () => {
  console.log("the port 3000 is running");
});
